home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / host / host.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-12-15  |  4.5 KB  |  173 lines

  1. /* 
  2.  * host.c --
  3.  *
  4.  *    This file contains a program that exercises the Host_
  5.  *    library procedures.  Invoke it with no parameters;  it
  6.  *    will print messages on stderr for any problems it detects
  7.  *    with the string procedures.
  8.  *
  9.  * Copyright 1988 Regents of the University of California
  10.  * Permission to use, copy, modify, and distribute this
  11.  * software and its documentation for any purpose and without
  12.  * fee is hereby granted, provided that the above copyright
  13.  * notice appear in all copies.  The University of California
  14.  * makes no representations about the suitability of this
  15.  * software for any purpose.  It is provided "as is" without
  16.  * express or implied warranty.
  17.  */
  18.  
  19. #ifndef lint
  20. static char rcsid[] = "$Header: /sprite/src/tests/host/RCS/host.c,v 1.2 88/12/15 09:27:17 ouster Exp $ SPRITE (Berkeley)";
  21. #endif not lint
  22.  
  23. #include <stdio.h>
  24. #include <host.h>
  25. #include <sys/types.h>
  26. #include <netinet/in.h>
  27. #include <arpa/inet.h>
  28.  
  29. #define error(string) \
  30.     fprintf(stderr, string); \
  31.     exit(1);
  32.  
  33. main()
  34. {
  35.     Host_Entry *entryPtr;
  36.     struct in_addr addr;
  37.     static unsigned char etherAddr[6] = {8, 0, 0x20, 1, 0x5c, 0xce};
  38.     int i;
  39.  
  40.     if (Host_SetFile("gorp") != -1) {
  41.     error("host error 1\n");
  42.     }
  43.     if (Host_SetFile("file1") != 0) {
  44.     error("host error 2\n");
  45.     }
  46.     entryPtr = Host_Next();
  47.     if (entryPtr == NULL) {
  48.     error("host error 3\n");
  49.     }
  50.     if (strcmp(entryPtr->name, "lust.Berkeley.EDU") != 0) {
  51.     error("host error 4\n");
  52.     }
  53.     if (strcmp(entryPtr->aliases[0], "lust") != 0) {
  54.     error("host error 5\n");
  55.     }
  56.     if (entryPtr->aliases[1] != 0) {
  57.     error("host error 6\n");
  58.     }
  59.     if (entryPtr->id != 1) {
  60.     error("host error 7\n");
  61.     }
  62.     if (entryPtr->netType != HOST_ETHER) {
  63.     error("host error 8\n");
  64.     }
  65.     if ((entryPtr->netAddr.etherAddr[0] != 8)
  66.         || (entryPtr->netAddr.etherAddr[1] != 0)
  67.         || (entryPtr->netAddr.etherAddr[2] != 0x20)
  68.         || (entryPtr->netAddr.etherAddr[3] != 1)
  69.         || (entryPtr->netAddr.etherAddr[4] != 2)
  70.         || (entryPtr->netAddr.etherAddr[5] != 0xc6)) {
  71.     error("host error 9\n");
  72.     }
  73.     if (entryPtr->inetAddr.s_addr != inet_addr("128.32.150.11")) {
  74.     error("host error 10\n");
  75.     }
  76.     Host_End();
  77.     entryPtr = Host_ByID(5);
  78.     if (entryPtr == NULL) {
  79.     error("host error 11\n");
  80.     }
  81.     if (strcmp(entryPtr->name, "basil.Berkeley.EDU") != 0) {
  82.     error("host error 12\n");
  83.     }
  84.     entryPtr = Host_ByID(108);
  85.     if (entryPtr != NULL) {
  86.     error("host error 13\n");
  87.     }
  88.     addr.s_addr = inet_addr("128.32.150.8");
  89.     entryPtr = Host_ByInetAddr(addr);
  90.     if (entryPtr == NULL) {
  91.     error("host error 14\n");
  92.     }
  93.     if (strcmp(entryPtr->name, "paprika.Berkeley.EDU") != 0) {
  94.     error("host error 15\n");
  95.     }
  96.     entryPtr = Host_ByInetAddr(46);
  97.     if (entryPtr != NULL) {
  98.     error("host error 16\n");
  99.     }
  100.     entryPtr = Host_ByName("mace.Berkeley.EDU");
  101.     if (entryPtr == NULL) {
  102.     error("host error 17\n");
  103.     }
  104.     if (entryPtr->id != 27) {
  105.     error("host error 18\n");
  106.     }
  107.     entryPtr = Host_ByName("oregano");
  108.     if (entryPtr == NULL) {
  109.     error("host error 19\n");
  110.     }
  111.     if (entryPtr->id != 38) {
  112.     error("host error 20\n");
  113.     }
  114.     entryPtr = Host_ByName("foobar");
  115.     if (entryPtr != NULL) {
  116.     error("host error 21\n");
  117.     }
  118.     entryPtr = Host_ByNetAddr(HOST_ETHER, (char *) etherAddr);
  119.     if (entryPtr == NULL) {
  120.     error("host error 22\n");
  121.     }
  122.     if (strcmp(entryPtr->name, "mint.Berkeley.EDU") != 0) {
  123.     error("host error 23\n");
  124.     }
  125.     etherAddr[0] = 0xff;
  126.     entryPtr = Host_ByNetAddr(HOST_ETHER, (char *) etherAddr);
  127.     if (entryPtr != NULL) {
  128.     error("host error 24\n");
  129.     }
  130.     if (Host_Start() != 0) {
  131.     error("host error 25\n");
  132.     }
  133.     for (i = 0; Host_Next() != NULL; i++) {
  134.     /* Null body. */
  135.     }
  136.     if (i != 33) {
  137.     error("host error 26\n");
  138.     }
  139.     Host_SetFile("file2");
  140.     if (Host_Next() != NULL) {
  141.     error("host error 27\n");
  142.     }
  143.     Host_SetFile("file3");
  144.     if (Host_Next() != NULL) {
  145.     error("host error 28\n");
  146.     }
  147.     Host_SetFile("file4");
  148.     if (Host_Next() != NULL) {
  149.     error("host error 29\n");
  150.     }
  151.     Host_SetFile("file5");
  152.     if (Host_Next() != NULL) {
  153.     error("host error 30\n");
  154.     }
  155.     Host_SetFile("file6");
  156.     if (Host_Next() != NULL) {
  157.     error("host error 31\n");
  158.     }
  159.     Host_SetFile("file7");
  160.     if (Host_Next() != NULL) {
  161.     error("host error 31\n");
  162.     }
  163.     Host_SetFile("file8");
  164.     entryPtr = Host_ByName("10");
  165.     if (entryPtr == NULL) {
  166.     error("host error 32\n");
  167.     }
  168.     entryPtr = Host_ByName("savory");
  169.     if (entryPtr == NULL) {
  170.     error("host error 33\n");
  171.     }
  172. }
  173.